package main

import (
	"fmt"

	code "gitee.com/youkelike/ziam/zcode/zcode"
	errors "gitee.com/youkelike/ziam/zerrors"
	log "gitee.com/youkelike/zlog"
)

func main() {
	if err := getUser(); err != nil {
		fmt.Printf("%+v\n", err)
	}
}

func getUser() error {
	if err := queryDatabase(); err != nil {
		return err
	}

	return nil
}

func queryDatabase() error {
	opts := &log.Options{
		Level:         "info",
		Format:        "console",
		EnableColor:   true,
		DisableCaller: false,
		OutputPaths:   []string{"test.log", "stdout"},
	}

	log.Init(opts)
	defer log.Sync()

	err := errors.WithCode(code.ErrDatabase, "user 'youkelike' not found.")
	if err != nil {
		log.Errorw("%+v", err)
	}
	return err
}
